/**
 * 改写自 https://github.com/antfu/eslint-config/blob/main/scripts/typegen.ts
 */
import { join } from 'node:path'
import typegen from 'eslint-typegen'
import { del, makeFile, readFile, writeFile } from 'void-fs'
import villv from '../src'

const config = await villv()

await del('src/typegen.ts')
await makeFile('src/typegen.ts')

await typegen(config, {
  dtsPath: join(process.cwd(), 'src', 'typegen.ts'),
  includeAugmentation: false,
})

const configNames = config.map((i) => i.name).filter(Boolean) as string[]

let dts = await readFile('src/typegen.ts')

dts += `
// Names of all the configs
export type ConfigNames = ${configNames.map((i) => `'${i}'`).join(' | ')}
`
await writeFile('src/typegen.ts', dts)
